﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;

using AimGameEngine.EditorObject;

using AimGameLibrary;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeOperatorsValue : NodeBaseControl
    {
        protected String NameValue1 = "NULL";
        protected String NameValue2 = "NULL";

        public NodeOperatorsValue(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw,MyListUpdateTime, MyListObject, MyListType)
	    {
            Connecter outputUpdate = new Connecter(inputspritebatch, inputcamera, Syco.Output, NodeTypeValue.Update, this);
            ListConnectpoint.Add(outputUpdate);

            Connecter inputValue1 = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Group_Value, this);
            ListConnectpoint.Add(inputValue1);

            Connecter inputValue2 = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Group_Value, this);
            ListConnectpoint.Add(inputValue2);
        }

        public override void SetupInput(Connecter Thisconnect, Connecter connectOutput)
        {
            switch (ListConnectpointInput.IndexOf(Thisconnect))
            {
                case 0: NameValue1 = connectOutput.MyNode.MyData.MyName; break;
                case 1: NameValue2 = connectOutput.MyNode.MyData.MyName; break;
            }
            MyData.Data = NameValue1 + "|" + NameValue2;
        }

        public override void ClearInput(Connecter ThisInputConnect, Connecter ThisConnectClear, string NameThisClear)
        {
            //base.ClearInput(ThisConnectClear, NameThisClear);
            MyData.Data = MyData.Data.Replace(NameThisClear, "NULL");
        }

        protected override Dictionary<string, NodeObject> GetDictionaryNode(Dictionary<string, NodeObject> TempNode)
        {
            if (NameValue1 != null)
                if (this.MyDictionaryObject.ContainsKey(NameValue1)) //&& !TempNode.ContainsKey(NameValue1)
                    TempNode.Add(NameValue1, this.MyDictionaryObject[NameValue1]);

            if (NameValue2 != null)
                if (this.MyDictionaryObject.ContainsKey(NameValue2)) //&& !TempNode.ContainsKey(NameValue2)
                    TempNode.Add(NameValue2, this.MyDictionaryObject[NameValue2]);

            return base.GetDictionaryNode(TempNode);
        }
    }
}
